package com.android.memory;
import com.android.memory.R;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;


/* Service for handling background music in the program
 */
public class MusicManagerService extends Service {
	public static MediaPlayer mpBackground;
	
	@Override
	 public void onCreate() {
	        super.onCreate();
	        // Sets music, looping and volume
	        mpBackground = MediaPlayer.create(this, R.raw.seb);
	        mpBackground.setLooping(true); // Set looping
	        mpBackground.setVolume(100,100);
	    }
	
	
	// Starts the music when startService() is run
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		mpBackground.start();
		return 1;
	}

	public static void stop() {
		mpBackground.stop();
	}
	
	public static void pause() {
		mpBackground.pause();
	}
	
	//Variables for fading out the music
	static float volume = 1;
	static float speed = 0.02f;

	// fades out the music
	public static void FadeOut()
	{
	    mpBackground.setVolume(volume, volume);
	    volume -= speed;

	}
	
	static boolean continueMusic = false;
	public static void setContinueMusic(boolean x) {
		continueMusic = x;
	}
	
	public static boolean getContinueMusic() {
		return continueMusic;
	}
	
	public void onDestroy() {
		mpBackground.stop();
		mpBackground.release();
    }
	
	
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}
}